package edu.sctu.xialei.june.day20150615one;

import java.io.File;
import java.io.IOException;
import java.util.Scanner;

/**
 * Created by Administrator on 2015/6/15.
 */

/*
文件操作类
 */
public class FileUtil {

    private File file;
    private String rootDir = "f://xialei_IO_File_tests//";
    private Scanner input = new Scanner(System.in);

    //    路径输入
    private void setPath() {
        String path = input.next();
        file = new File(rootDir + path);
    }


//    create File method
    public void createFile() {
        setPath();

        if (!file.exists()) {
            try {
                file.createNewFile();
            } catch (IOException e) {
                e.printStackTrace();
            }
        } else {
            System.out.println("the File you typed is already existed");
        }
    }

//    delete File or Folder method
    public void deleteFileOrFolder() {
        setPath();

        if (file.exists()) {
            file.delete();
        } else {
            System.out.println("the File or Folder path you typed is not existed");
        }
    }

//    create Folder method
    public void createFolder() {
        setPath();

        if (!file.exists()) {
            file.mkdirs();
        } else {
            System.out.println("the Folder you typed is existing");
        }
    }
}
